package com.sky.config;


import com.aliyun.oss.AliOSSUtilsPropertiesPojo;
import com.sky.utils.AliOssUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

@Slf4j
@Component
@Configuration
@EnableConfigurationProperties(AliOSSUtilsPropertiesPojo.class)//开启配置属性,将AliOSSUtilsPropertiesPojo类注入到spring容器中
public class AliyunOssConfiguration {
    //配置阿里云OSS工具类，并注入到spring容器的bean
    @Bean
    public AliOssUtil ossClient(AliOSSUtilsPropertiesPojo ossProperties) {//通过形参把在spring容器中的AliOSSUtilsPropertiesPojo类注入到ossClient方法中
        log.info(">>>>>>>>>>开始配置阿里云OSS工具类的bean>>>>>>>>>");
        AliOssUtil ossUtil = AliOssUtil.of(ossProperties.getEndpoint(), ossProperties.getAccessKeyId(), ossProperties.getAccessKeySecret(), ossProperties.getBucketName());//形参传递的是其他bean组件对应的类的对象,直接传递不用@Autowired进行注入
        return ossUtil;//把ossUtil对象返回,注入到spring容器中
    }

}
